package xy.strategy.design.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 环境或者上下文类，用于统一执行具体策略
 */
@Component
public class SeasonsFactory {
    /**
     * Spring会自动将Strategy接口的实现类注入到这个Map中，key为bean id，value值则为对应的策略实现类
     */
    @Autowired
    private Map<String, SeasonsStrategy> seasonsMap;

    /**
     * 处理四季统一入口方法
     *
     * @param seasons
     * @param beanName
     * @return
     */
    public String handle(String seasons, String beanName) {
        // 根据bean的名称获取对应的算法处理类
        SeasonsStrategy seasonsStrategy = seasonsMap.get(beanName);
        String execute = seasonsStrategy.execute(seasons);
        return execute;
    }
}
